package com.xxx.reggie.mapper;


import com.xxx.reggie.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CategoryMapper {

    //根据类别名称查询类别对象
    @Select("SELECT * FROM category WHERE NAME=#{name}")
    Category findByName(String name);

    //添加类别
    @Insert("insert into category " +
            "values(null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer save(Category category);

    //查询类别所有数据,根据sort字段排序
    @Select("SELECT * FROM category  ORDER BY sort")
    List<Category> findByPage();

    //删除菜品
    @Delete("delete from category where id=#{id}")
    Integer deleteById(long id);

    //修改类别
    @Update("update category " +
            "set name=#{name},sort=#{sort},update_user=#{updateUser},update_time=#{updateTime} " +
            "where id=#{id}")
    Integer updateCategory(Category category);

    //根据name查询对应类别数量,排除当前自己类别
    @Select("select count(*) from category where name=#{name} and id!=#{id}")
    Integer selectByNameCount(Category category);

    //查询所有菜品
    List<Category> list(@Param("type") Integer type);


    //根据cid查询类别对象
    @Select("select * from category where id=#{cid}")
    Category findByCid(Long cid);
}
